package com.sdkx.app.datalayers;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;

import cn.creable.gridgis.util.Image;

import com.sdkx.app.R;
import com.sdkx.app.gps.GpsManager;

import java.util.Vector;

import cn.creable.gridgis.display.Display;
import cn.creable.gridgis.display.LineSymbol;
import cn.creable.gridgis.geodatabase.Feature;
import cn.creable.gridgis.geodatabase.FeatureClass;
import cn.creable.gridgis.geodatabase.IFeature;
import cn.creable.gridgis.geometry.GeometryType;
import cn.creable.gridgis.geometry.LineString;
import cn.creable.gridgis.geometry.Point;

public class FlyDirectPanel extends MapDraw {
    private Paint paint;
    Point endPoint;
    LineSymbol lineSymbol = new LineSymbol();
    FeatureClass  featureClass;
    String pointName;
    Image endImage;
    public FlyDirectPanel(Context context) {
        super(context);
        paint = new Paint();
        paint.setTextSize(25);
        paint.setColor(0xFFFF0000);
        lineSymbol.setColor(0xFF00FF00);
        lineSymbol.setWidth(5);
        featureClass = new FeatureClass(new String[]{"text"}, GeometryType.Point);
        BitmapDrawable bmpDraw = (BitmapDrawable) appContext.getResources().getDrawable(R.drawable.winningflag);
        endImage = new Image(bmpDraw.getBitmap());
        // IFeature地图要素
//        Vector<IFeature> fts = new Vector<IFeature>();
////        for (int i = 0; i < pts.length; ++i) {
////            // IGeometry几何类型接口
////            // 地图要素，是地图上的所有形状地图要素的抽象。
////            IFeature ft = new Feature(pts[i], new String[]{text[i]});
////            fts.addElement(ft);
////        }
        // 设置全部地图要素
//        fc.setFeatures(fts);
    }
    @Override
    protected void draw2(Canvas canvas, Display display) {
        if(featureClass.getFeatureCount() == 0){
            Vector<IFeature> fts = new Vector<IFeature>();
            IFeature ft = new Feature(endPoint, new String[]{pointName});
            fts.addElement(ft);
            featureClass.setFeatures(fts);
        };
        LineString line=new LineString(2,null);
        Location  location = GpsManager.getInstance().getLocation();
        if(location == null)
            line.setPoint(0,mDefaultPoint);
        else {
            line.setPoint(0, new Point(location.getLongitude(), location.getLatitude()));
        }
        line.setPoint(1,endPoint);
        Canvas oldG = display.getCanvas();
        display.setCanvas(canvas);
        display.DrawPolyline(line,lineSymbol);
        display.DrawImagePoint(endPoint,endImage);
        display.setCanvas(oldG);
        display.setLabelSize(20);
        display.setLabelColor(Color.RED);
        display.labelFeatureClass(canvas, featureClass, 0, endImage.getWidth(), endImage.getWidth() / 4);
//        double length =111.1*Math.cos(pts[0].getY()*Math.PI/180);
//        double lon = pts[0].getX()+10/length;
//        double lat = pts[0].getY();
//        Point oncercal = new Point(lon,lat);
//        double cicledis1 =   Arithmetic.Distance(pts[0],pts[1],(byte)1);
//        double cicledis =   Arithmetic.Distance(pts[0],oncercal,(byte)1);
//        LineString lines = Arithmetic.makeCircle(pts[0],oncercal,180);
//        d.DrawPolyline(lines,lineSymbol);
    }
    public void setEndPoint(Point endPoint) {
        this.endPoint = endPoint;
    }
    public void setPointName(String pointName) {
        this.pointName = pointName;
    }

}
